<?php
namespace pay;

use think\facade\Env;

/**
 * Created by PhpStorm.
 * User: shenzhe
 * Date: 2019/4/3
 * Time: 16:21
 */
abstract class Api {
    protected $appId = null;
    protected $appSecret = null;
    protected $mchId = null;
    protected $mchKey = null;
    protected $accessToken = null;
    protected $pay_platform = null;

    protected $notice_result = true; //bool
    protected $notice_result_msg = '';

    protected $prepayId = null;
    protected $transactionId = null;

    protected $order_id=null;
    protected $order_body=null;
    protected $pay_fee=null;
    protected $notify_url=null;
    protected $client_ip=null;
    protected $open_id=null;
    protected $trade_type=null;
    protected $attach='';

    protected $refund_id=null;
    protected $refund_fee=null;

    public function __construct($appId=null,$mchId=null,$mchKey=null,$appSecret=null)
    {
        $this->appId = $appId;
        $this->mchId = $mchId;
        $this->mchKey = $mchKey;
        $this->appSecret = $appSecret;
    }

    public static function createByPlatform($platform){
        if($platform == 1){
            return new Wx(
                Env::get('weixin.appid_home')
                ,Env::get('weixin.app_home_merchantid')
                ,Env::get('weixin.app_home_merchantkey')
                ,Env::get('weixin.app_home_secret')
            );
        }
    }

    /**
     * 预生成订单
     * @return mixed
     */
    abstract public function unifiedOrder();

    /**
     * 生成支付参数
     * @return mixed
     */
    abstract public function getJsApiPayParams();
    /**
     * 验证回调信息
     * @return mixed
     */
    abstract public function check_notify();
    /**
     * 处理支付方返回
     * @return mixed
     */
    abstract public function return_notify();
    /**
     * @return null
     */
    public function getAppId()
    {
        return $this->appId;
    }

    /**
     * @param null $appId
     */
    public function setAppId($appId)
    {
        $this->appId = $appId;
    }

    /**
     * @return null
     */
    public function getMchId()
    {
        return $this->mchId;
    }

    /**
     * @param null $mchId
     */
    public function setMchId($mchId)
    {
        $this->mchId = $mchId;
    }

    /**
     * @return null
     */
    public function getMchKey()
    {
        return $this->mchKey;
    }

    /**
     * @param null $mchKey
     */
    public function setMchKey($mchKey)
    {
        $this->mchKey = $mchKey;
    }

    /**
     * @return null
     */
    public function getPrepayId()
    {
        return $this->prepayId;
    }

    /**
     * @param null $prepayId
     */
    public function setPrepayId($prepayId)
    {
        $this->prepayId = $prepayId;
    }

    /**
     * @return null
     */
    public function getTransactionId()
    {
        return $this->transactionId;
    }

    /**
     * @param null $transactionId
     */
    public function setTransactionId($transactionId)
    {
        $this->transactionId = $transactionId;
    }

    /**
     * @return null
     */
    public function getOrderId()
    {
        return $this->order_id;
    }

    /**
     * @param null $order_id
     */
    public function setOrderId($order_id)
    {
        $this->order_id = $order_id;
    }

    /**
     * @return mixed
     */
    public function getOrderBody()
    {
        return $this->order_body;
    }

    /**
     * @param mixed $order_body
     */
    public function setOrderBody($order_body)
    {
        $this->order_body = $order_body;
    }

    /**
     * @return mixed
     */
    public function getPayFee()
    {
        return $this->pay_fee;
    }

    /**
     * @param mixed $pay_fee
     */
    public function setPayFee($pay_fee)
    {
        $this->pay_fee = $pay_fee;
    }

    /**
     * @return mixed
     */
    public function getNotifyUrl()
    {
        return $this->notify_url;
    }

    /**
     * @param mixed $notify_url
     */
    public function setNotifyUrl($notify_url)
    {
        $this->notify_url = $notify_url;
    }

    /**
     * @return mixed
     */
    public function getClientIp()
    {
        return $this->client_ip;
    }

    /**
     * @param mixed $client_ip
     */
    public function setClientIp($client_ip)
    {
        $this->client_ip = $client_ip;
    }

    /**
     * @return mixed
     */
    public function getOpenId()
    {
        return $this->open_id;
    }

    /**
     * @param mixed $open_id
     */
    public function setOpenId($open_id)
    {
        $this->open_id = $open_id;
    }

    /**
     * @return string
     */
    public function getTradeType()
    {
        return $this->trade_type;
    }

    /**
     * @param string $trade_type
     */
    public function setTradeType($trade_type)
    {
        $this->trade_type = $trade_type;
    }

    /**
     * @return string
     */
    public function getAttach()
    {
        return $this->attach;
    }

    /**
     * @param string $attach
     */
    public function setAttach($attach)
    {
        $this->attach = $attach;
    }

    /**
     * @return null
     */
    public function getRefundId()
    {
        return $this->refund_id;
    }

    /**
     * @param null $refund_id
     */
    public function setRefundId($refund_id)
    {
        $this->refund_id = $refund_id;
    }

    /**
     * @return null
     */
    public function getRefundFee()
    {
        return $this->refund_fee;
    }

    /**
     * @param null $refund_fee
     */
    public function setRefundFee($refund_fee)
    {
        $this->refund_fee = $refund_fee;
    }

    /**
     * @return null
     */
    public function getPayPlatform()
    {
        return $this->pay_platform;
    }

    /**
     * @param null $pay_platform
     */
    public function setPayPlatform($pay_platform)
    {
        $this->pay_platform = $pay_platform;
    }

    /**
     * @return bool
     */
    public function getNoticeResult()
    {
        return $this->notice_result;
    }

    /**
     * @param bool $notice_result
     */
    public function setNoticeResult($notice_result)
    {
        $this->notice_result = $notice_result;
    }

    /**
     * @return string
     */
    public function getNoticeResultMsg()
    {
        return $this->notice_result_msg;
    }

    /**
     * @param string $notice_result_msg
     */
    public function setNoticeResultMsg($notice_result_msg)
    {
        $this->notice_result_msg = $notice_result_msg;
    }

}